function _toConsumableArray(t) {
  if (Array.isArray(t)) {
      for (var e = 0, a = Array(t.length); e < t.length; e++) a[e] = t[e];
      return a;
  }
  return Array.from(t);
}

var g, pages, app = getApp(), page = app.page, request = app.util.request;

function getList() {
  var t = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : -1, a = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : 1;
  request({
      url: "NewsLawList",
      data: {
          type_id: t,
          page: a,
          number: app.config.news_number
      },
      showLoading: !1,
      success: function(t) {
          wx.stopPullDownRefresh();
          var e = g.data.news_list;
          e && 1 != a && (t = [].concat(_toConsumableArray(e), _toConsumableArray(t))), g.setData({
              news_list: t
          }), t.length && a * app.config.news_number >= t[0].num && g.setData({
              isLoad: !0
          });
      }
  });
}

page({
  data: {
      TabCur: -1,
      isLoad: !1
  },
  onLoad: function(t) {
      pages = 1, (g = this).options && g.options.id ?  wx.setNavigationBarTitle({
          title: g.options.title || "新闻"
      }) : ''
      request({
          url: "NewsType",
          showLoading: !1,
          success: function(t) {
              // {
              //     id: -1,
              //     title: "全部"
              // } 
              g.setData({
                  news_type: [ ].concat(_toConsumableArray(t))
              }) 
              if(g.options.id){
                  let TabCur = g.data.news_type.findIndex((item)=>{return item.id == g.options.id})
                  g.setData({
                      TabCur
                  })
              }
              getList(g.options.id)
          }
      });
     
      
  },
  onPullDownRefresh: function() {
      g.setData({
          TabCur: 0,
          isLoad: !1
      }), g.onLoad();
  },
  onReachBottom: function() {
      !g.data.isLoad && pages++ && getList(g.data.news_type[g.data.TabCur].id, pages);
  },
  tabSelect: function(t) {
      t = t.currentTarget.dataset.item, g.setData({
          TabCur: t[0],
          isLoad: !1
      }), getList(t[pages = 1]);
  },
  onShareAppMessage: function(t) {
      return {
          title: g.data.system.xcx_name,
          path: g.route + "?pid=" + app.userInfo.id
      };
  },
  onShareTimeline: function() {
      return {
          title: g.data.system.xcx_name,
          query: "pid=" + app.userInfo.id
      };
  }
});